
def is_simple(x):
    #return all(x%d == 0 for d in range(2, int(x**(0.5))+1))
    for d in range(2, int(x**(0.5))+1): #range(2, x)
        if x%d == 0: return False
    return True
def spr():
    sp = []
    for i in range(101, 998):
        if is_simple(i) == 1: #== True: #== 1:
            sp.append(i)
    #sp = [d for d in range(101, 998) if is_simple(d)]
    return sp

w_digits = dict({'zero':'0', 'one':'1', 'two':'2', 'three':'3', 'four':'4',\
                'five':'5', 'six':'6', 'seven':'7', 'eight':'8', 'nine':'9'})
s = input()
sw = s.split()
p = ''
for g in sw:
    p += w_digits[g]
    
if len(p) != 3:
    print('Wrong input')
else:
    a = max(x for x in spr() if x <= int(p))
    b = min(x for x in spr() if x >= int(p))
    if abs(int(p) - a) > abs(int(p) - b):
        print(b)
    else: print(a)
